const gulp=require("gulp");
// const uglify=require("gulp-uglify");
const webserver=require("gulp-webserver");
const sass=require("gulp-sass");

gulp.task("server",["static"],()=>{
	gulp.src("dist")
	.pipe(webserver({
		livereload:true,
		proxies:[
			{
				source:"/hyg",
				target:"http://www.yiguo.com/Handler/InitLayOut?r=0.5975008154800805&_=1567574017602"
			}
		]
	}))
	gulp.watch("src/pages/**/*.js",["complieJS"]);
	gulp.watch("src/scripts/**/*.js",["complieJS"]);
	gulp.watch("src/conf/**/*.js",["complieJS"]);
	gulp.watch("src/pages/**/*.html",["complieHTML"]);
	gulp.watch("src/styles/**/*.scss",["complieCSS"]);
})
gulp.task("complieCSS",()=>{
	gulp.src("src/styles/**/*.scss")
	.pipe( sass().on('error',sass.logError))
	.pipe( gulp.dest("dist/styles/"))	
})
gulp.task("complieJS",()=>{
	gulp.src("src/pages/**/*.js")
	// .pipe(uglify())
	.pipe(gulp.dest("dist/pages/"))
	gulp.src("src/scripts/**/*.js")
	// .pipe(uglify())
	.pipe(gulp.dest("dist/scripts/"))
	gulp.src("src/conf/**/*.js")
	// .pipe(uglify()) 
	.pipe(gulp.dest("dist/conf/"))
})
gulp.task("complieHTML",()=>{
	gulp.src("src/pages/**/*.html")
	.pipe(gulp.dest("dist/pages/"))
})
gulp.task("static",()=>{
	gulp.src("src/static/**/*.*")
	.pipe(gulp.dest("dist/static/"))
})
